#include "Parser.h"

Parser::Parser()
{

}
Parser::COMMAND Parser::parsecommand(std::string cmd)
{
    Parser::COMMAND tmpcmd;
    int valcounter;
    int pos=0;
    int tmppos = 0;
    std::string tmp;
    if (cmd.at(0) == '/' || cmd.at(1)=='/')
    {
        tmpcmd.command = COMMENT;
        return tmpcmd;
    }
    pos = cmd.find_first_of(" \n", 0);
    for (int i=0;i<pos;i++) tmp+=cmd.at(i);
    if (tmp == "CREATE_MAP") tmpcmd.command = CREATE_MAP;
    if (tmp == "FILL_BACKGROUND") tmpcmd.command = FILL_BACKGROUND;
    switch(tmpcmd.command)
    {
        case CREATE_MAP:
        {
            tmpcmd.command = CREATE_MAP;
            tmppos = pos;
            pos = cmd.find_first_of(" ", tmppos+1);
            for (int i=tmppos+1;i<pos;i++) tmpcmd.str1+=cmd.at(i);
            tmppos = pos;
            tmp.clear();
            pos = cmd.find_first_of(" ", tmppos+1);
            for (int i=tmppos+1;i<pos;i++) tmp+=cmd.at(i);
            tmpcmd.val1 = atoi(tmp.c_str());
            tmppos = pos;
            tmp.clear();
            pos = cmd.length();
            for (int i=tmppos+1;i<pos;i++) tmp+=cmd.at(i);
            tmpcmd.val2 = atoi(tmp.c_str());
            break;
        }
        default:
            tmpcmd.command = COMMENT;
    }

    return tmpcmd;
}
